package response

import (
	"gin-skeleton/etc"
	"github.com/sirupsen/logrus"
	"net/http"

	"github.com/gin-gonic/gin"
)

type ViewData struct {
	c    *gin.Context
	Tpl  string
	Data map[string]interface{}
}

// View 实例化视图响应
func View(c *gin.Context) *ViewData {
	return &ViewData{
		c: c,
	}
}

func (v *ViewData) Render(tpl string, data map[string]interface{}){

	v.Tpl = tpl
	v.Data = data

	if !etc.Load().View.Enable {
		logrus.Warnln("The view function is disabled")
		return
	}
	v.c.HTML(http.StatusOK, v.Tpl, v.Data)
}
